package com.hc.comm.utils;

import java.awt.Color;
import java.awt.Font;
import java.util.Random;

import org.apache.commons.codec.digest.DigestUtils;


public class SecurityCode {
	
	private static final String BASE_CHECK_CODE = "0123456789abcdefghijklnmopqrstuvwxyz";
	
	//字体
	private static Font font = new Font("segoescb", Font.BOLD, 22);
	
	/**
	* @Title: getRandomColor
	* @Description: TODO
	* @return 随机颜色
	 */
	private static Color getRandomColor(int fc, int bc){
		Random random = new Random();
		fc = (fc > 255) ? 255 : fc;
		bc = (bc > 255) ? 255 : bc;
		int r = fc + random.nextInt(bc - fc);
		int g = fc + random.nextInt(bc - fc);
		int b = fc + random.nextInt(bc - fc);
		return new Color(r, g, b);
	}
	
	

	
	/**
	* @Title: getRandomCode
	* @Description: 获取随机数字符串
	* @param length 生成字符串的长度
	* @return String   
	 */
	public static String getRandomCode(int length){
		if(length <= 0){
			return null;
		}
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < length; i++) {
			sb.append(BASE_CHECK_CODE.charAt((int) Math.floor(Math.random() * BASE_CHECK_CODE.length())));
		}
		return sb.reverse().toString().toUpperCase();
	}
	
	/**
	* @Title: getRandomNumber
	* @Description: 获取数字验证码
	* @param length
	* @return String
	 */
	public static String getRandomNumber(int length){
		if(length <= 0){
			return null;
		}
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < length; i++) {
			sb.append((int) Math.floor(Math.random() * 10));
		}
		return sb.reverse().toString();
	}
	
	
	/**
	* @Title: passwordMD5
	* @Description: 密码加盐加密
	* @param password
	* @param salt
	* @return String
	 */
	public static String passwordMD5(String password, String salt){
		return DigestUtils.md5Hex(DigestUtils.md5Hex(password) + salt);
	}

	
}
